#include <unistd.h>
#include <sys/time.h>
#include "common.h"

size_t getGpuGlobalMem(int deviceID){
        size_t free = 0, total = 0;

        cudaMemGetInfo(&free,&total);
        return free;
}

long getAvailMem(void){
	long mem = sysconf(_SC_AVPHYS_PAGES) * sysconf(_SC_PAGE_SIZE);
	return mem;
}

double getCurrentTime(void){
	struct timeval tv;
        gettimeofday(&tv, NULL);
        double curr  = (tv.tv_sec) * 1000 + (tv.tv_usec) / 1000 ;
	return curr;
}

void freeRel(struct relation * rel){
	free(rel->whereAttrType);
	free(rel->whereAttrSize);
	for(int i=0;i<rel->whereAttrNum;i++){
		free(rel->content[i]);
	}
	free(rel->filter);
	free(rel->content);
}

void freeTable(struct tableNode * tn){
	free(tn->attrType);
	free(tn->attrSize);
	for(int i=0;i<tn->totalAttr;i++){
		free(tn->content[i]);
	}
	free(tn->content);
}
